package com.androidx.p013lv.base.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
import com.androidx.p013lv.base.C1010R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.bumptech.glide.request.target.ImageViewTarget;
import com.luck.picture.lib.engine.ImageEngine;
import com.luck.picture.lib.listener.OnImageCompleteCallback;
import com.luck.picture.lib.tools.MediaUtils;
import com.luck.picture.lib.widget.longimage.ImageSource;
import com.luck.picture.lib.widget.longimage.ImageViewState;
import com.luck.picture.lib.widget.longimage.SubsamplingScaleImageView;

/* renamed from: com.androidx.lv.base.utils.GlideEngine */
public class GlideEngine implements ImageEngine {
    private static GlideEngine instance;

    @Override // com.luck.picture.lib.engine.ImageEngine
    public void loadImage(Context context, String str, ImageView imageView) {
        Glide.with(context).load(str).into(imageView);
    }

    @Override // com.luck.picture.lib.engine.ImageEngine
    public void loadImage(Context context, String str, final ImageView imageView, final SubsamplingScaleImageView subsamplingScaleImageView, final OnImageCompleteCallback onImageCompleteCallback) {
        Glide.with(context).asBitmap().load(str).into(new ImageViewTarget<Bitmap>(imageView) {
            /* class com.androidx.p013lv.base.utils.GlideEngine.C10511 */

            @Override // com.bumptech.glide.request.target.BaseTarget, com.bumptech.glide.request.target.ViewTarget, com.bumptech.glide.request.target.Target, com.bumptech.glide.request.target.ImageViewTarget
            public void onLoadStarted(Drawable drawable) {
                super.onLoadStarted(drawable);
            }

            @Override // com.bumptech.glide.request.target.BaseTarget, com.bumptech.glide.request.target.Target, com.bumptech.glide.request.target.ImageViewTarget
            public void onLoadFailed(Drawable drawable) {
                super.onLoadFailed(drawable);
            }

            /* access modifiers changed from: protected */
            public void setResource(Bitmap bitmap) {
                OnImageCompleteCallback onImageCompleteCallback = onImageCompleteCallback;
                if (onImageCompleteCallback != null) {
                    onImageCompleteCallback.onHideLoading();
                }
                if (bitmap != null) {
                    boolean isLongImg = MediaUtils.isLongImg(bitmap.getWidth(), bitmap.getHeight());
                    int i = 8;
                    subsamplingScaleImageView.setVisibility(isLongImg ? 0 : 8);
                    ImageView imageView = imageView;
                    if (!isLongImg) {
                        i = 0;
                    }
                    imageView.setVisibility(i);
                    if (isLongImg) {
                        subsamplingScaleImageView.setQuickScaleEnabled(true);
                        subsamplingScaleImageView.setZoomEnabled(true);
                        subsamplingScaleImageView.setPanEnabled(true);
                        subsamplingScaleImageView.setDoubleTapZoomDuration(100);
                        subsamplingScaleImageView.setMinimumScaleType(2);
                        subsamplingScaleImageView.setDoubleTapZoomDpi(2);
                        subsamplingScaleImageView.setImage(ImageSource.bitmap(bitmap), new ImageViewState(0.0f, new PointF(0.0f, 0.0f), 0));
                        return;
                    }
                    imageView.setImageBitmap(bitmap);
                }
            }
        });
    }

    @Override // com.luck.picture.lib.engine.ImageEngine
    public void loadImage(Context context, String str, final ImageView imageView, final SubsamplingScaleImageView subsamplingScaleImageView) {
        Glide.with(context).asBitmap().load(str).into(new ImageViewTarget<Bitmap>(imageView) {
            /* class com.androidx.p013lv.base.utils.GlideEngine.C10522 */

            /* access modifiers changed from: protected */
            public void setResource(Bitmap bitmap) {
                if (bitmap != null) {
                    boolean isLongImg = MediaUtils.isLongImg(bitmap.getWidth(), bitmap.getHeight());
                    int i = 8;
                    subsamplingScaleImageView.setVisibility(isLongImg ? 0 : 8);
                    ImageView imageView = imageView;
                    if (!isLongImg) {
                        i = 0;
                    }
                    imageView.setVisibility(i);
                    if (isLongImg) {
                        subsamplingScaleImageView.setQuickScaleEnabled(true);
                        subsamplingScaleImageView.setZoomEnabled(true);
                        subsamplingScaleImageView.setPanEnabled(true);
                        subsamplingScaleImageView.setDoubleTapZoomDuration(100);
                        subsamplingScaleImageView.setMinimumScaleType(2);
                        subsamplingScaleImageView.setDoubleTapZoomDpi(2);
                        subsamplingScaleImageView.setImage(ImageSource.bitmap(bitmap), new ImageViewState(0.0f, new PointF(0.0f, 0.0f), 0));
                        return;
                    }
                    imageView.setImageBitmap(bitmap);
                }
            }
        });
    }

    @Override // com.luck.picture.lib.engine.ImageEngine
    public void loadFolderImage(final Context context, String str, final ImageView imageView) {
        ((RequestBuilder) ((RequestBuilder) ((RequestBuilder) Glide.with(context).asBitmap().load(str).override(180, 180)).centerCrop()).sizeMultiplier(0.5f)).apply(new RequestOptions().placeholder(C1010R.C1012drawable.picture_image_placeholder)).into(new BitmapImageViewTarget(imageView) {
            /* class com.androidx.p013lv.base.utils.GlideEngine.C10533 */

            /* access modifiers changed from: protected */
            @Override // com.bumptech.glide.request.target.BitmapImageViewTarget
            public void setResource(Bitmap bitmap) {
                RoundedBitmapDrawable create = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
                create.setCornerRadius(8.0f);
                imageView.setImageDrawable(create);
            }
        });
    }

    @Override // com.luck.picture.lib.engine.ImageEngine
    public void loadAsGifImage(Context context, String str, ImageView imageView) {
        Glide.with(context).asGif().load(str).into(imageView);
    }

    @Override // com.luck.picture.lib.engine.ImageEngine
    public void loadGridImage(Context context, String str, ImageView imageView) {
        ((RequestBuilder) ((RequestBuilder) Glide.with(context).load(str).override(200, 200)).centerCrop()).apply(new RequestOptions().placeholder(C1010R.C1012drawable.picture_image_placeholder)).into(imageView);
    }

    private GlideEngine() {
    }

    public static GlideEngine createGlideEngine() {
        if (instance == null) {
            synchronized (GlideEngine.class) {
                if (instance == null) {
                    instance = new GlideEngine();
                }
            }
        }
        return instance;
    }
}
